package com.caigou.controller;

import com.caigou.annotation.OperLog;
import com.caigou.bean.cms.entity.Comment;
import com.caigou.bean.cms.param.CommentFilterParam;
import com.caigou.bean.cms.param.CommentParam;
import com.caigou.bean.exam.entity.Users;
import com.caigou.constant.NewsConstant;
import com.caigou.enums.FailResultEnum;
import com.caigou.security.utils.CurrentUser;
import com.caigou.service.ICommentService;
import com.caigou.util.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController {

    @Resource
    private ICommentService commentService;

//    @GetMapping("/article/query")
//    public Result<List<Comment>> findCommentByCommentTargetId(CommentParam param, @CurrentUser Users user) {
//        return commentService.findCommentByCommentTargetId(param);
//    }

    @OperLog(operModule = NewsConstant.COMMENT_MODULE, operType = NewsConstant.ADD_OPERATION, operDesc = "增加文章评论")
    @PostMapping("/article/add")
    public Result<Integer> addCommentByComment(@RequestBody CommentParam param, @CurrentUser Users user) {
        return commentService.addCommentByComment(param, user);
    }

    @OperLog(operModule = NewsConstant.COMMENT_MODULE, operType = NewsConstant.DELETE_OPERATION, operDesc = "删除文章评论")
    @PostMapping("/article/delete")
    @PreAuthorize("hasAnyAuthority('shanchupinglun')")
    public Result<Integer> deleteCommentByComment(@RequestBody CommentParam param, @CurrentUser Users user) {
        return commentService.deleteCommentByComment(param);
    }

    /**
     * 用户根据参数条件查询用户评论信息
     *
     * @param param
     * @param
     * @return
     */
    @PostMapping("/article/param/query")
    @PreAuthorize("hasAnyAuthority('chakanpinglun')")
    public Result<PageInfo<Comment>> findCommentByParam(@RequestBody  CommentFilterParam param) {
        return commentService.findCommentByParam(param);
    }


}
